package org.tagging.service;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.tagging.model.Abbreviation;
import org.tagging.model.Tagging;
import org.tagging.model.TaggingIndonesian;
import org.tagging.model.UnknownWord;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface TaggingService<T> {
    List<T> list(Integer size);

    void clearUsingBy(Integer tagId);

    void translate(Integer id, String translation);

    List<T> listNotTranslate(Integer size);

    List<T> listNotAbbreviate(Integer size);

    List<T> listNotUnknownWord(Integer size);

    void updateSelective(T tagging);

    void updateUpdateByAndTranslated(Integer id);

    void updateUpdateByAndAbbreviation(Integer tagId);

    void updateUpdateByAndUnknownWord(Integer tagId);

    List<T> queryByTimePeriod(LocalDateTime startTime, LocalDateTime endTime,int mode);

    Workbook constructWorkbookByTimePeriod(LocalDateTime startTime, LocalDateTime endTime,int mode);

//    int construct(int i, Class<? extends Tagging> taggingClazz);

    default Map<String, Integer> preConstruct(
            Class<? extends Tagging> taggingClazz,
            Set<String> skipFields) {
        Map<String, Integer> map = new HashMap<>();
        int i = 0;
        i = construct(map, skipFields, i, taggingClazz);
        i=construct(map,skipFields,i,taggingClazz.getSuperclass());
//        i = construct(map, skipFields, i, abbreviationClazz);
//        i = construct(map, skipFields, i, unknownWordClazz);
        return map;
    }

    default int construct(Map<String, Integer> map, Set<String> skipFields,
                          int i, Class<?> clazz) {
        Field[] declaredFields = clazz.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            if (skipFields.contains(declaredField.getName())) {
                continue;
            }
            map.put(declaredField.getName(), i++);
        }
        return i;
    }



    default String toCapital(String name) {
        return (char) (name.charAt(0) & '_') + name.substring(1);
    }
}
